/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sdd.facades.factories;

import com.sdd.entities.Orderr;
import com.sdd.entities.OrderItem;
import com.sdd.plains.CartPlain;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;

/**
 *
 * @author Fernando
 */
@LocalBean
@Stateless
public class OrderFactoryFacadeBean {
    @EJB
    OrderItemFactoryFacadeBean orderItemFactoryFacadeBean;
    
    public CartPlain createCartPlain(Orderr order) {
        if(order == null) return null;
        CartPlain cart = new CartPlain();
        cart.setId(order.getId());
        Iterator<OrderItem> it = order.getOrderItems().iterator();
        while(it.hasNext()) {
            cart.addToCart(orderItemFactoryFacadeBean.createCartItem(it.next()));
        }
        return cart;
    } 
    
    public List<CartPlain> createCartPlains(List<Orderr> list) {
        if(list == null) return null;
        ArrayList<CartPlain> newList = new ArrayList<CartPlain>();
        Iterator<Orderr> it = list.iterator();
        while(it.hasNext()) {
            newList.add(createCartPlain(it.next()));
        }
        return newList;
    }
}
